package com.sz.ac.model.constant;

/**
 * @author ruichar
 * 接口全局返回信息
 */
public class ResultData 
{
	
	public static final int SUCCESS = 200;
	
	public static final int ERROR = 400;
	//重定向
	public static final int REDIRECT = 302;
	
	/**
     * 业务码
     */
    private int errno;	//200代表成功，400代表失败

    /**
     * 返回时间戳
     */
    private String time = System.currentTimeMillis() + "";
    
    /**
     * 返回的消息描述
     */
    private String errmsg;

    /**
     * 返回内容
     */
    private Object data;
    
	public ResultData() 
	{
		
	}
	public ResultData(Object data) 
	{
		this.data = data;
	}
	public static ResultData success(Object data,int errorCode,String errorMsg)
	{
		ResultData rsData = new ResultData();
		rsData.setData(data);
		rsData.setErrmsg(errorMsg);
		rsData.setErrno(errorCode);
		return rsData;
	}
	public static ResultData success(Object data)
	{
		ResultData rsData = new ResultData();
		rsData.setData(data);
		rsData.setErrmsg("成功");
		rsData.setErrno(SUCCESS);
		return rsData;
	}
	public static ResultData error(Object data,String errorMsg) 
	{
		ResultData rsData = new ResultData();
		rsData.setData(data);
		rsData.setErrno(ERROR);
		rsData.setErrmsg(errorMsg);
		return rsData;
	}
	public static ResultData error(Object data,int errorCode,String errorMsg) 
	{
		ResultData rsData = new ResultData();
		rsData.setData(data);
		rsData.setErrno(errorCode);
		rsData.setErrmsg(errorMsg);
		return rsData;
	}
	public static ResultData error(String errorMsg) 
	{
		ResultData rsData = new ResultData();
		rsData.setErrno(ERROR);
		rsData.setErrmsg(errorMsg);
		return rsData;
	}
	public static ResultData error() 
	{
		ResultData rsData = new ResultData();
		rsData.setErrno(ERROR);
		rsData.setErrmsg("系统错误");
		return rsData;
	}

	public int getErrno() {
		return errno;
	}

	public void setErrno(int errno) {
		this.errno = errno;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
	
	public String getErrmsg() {
		return errmsg;
	}
	public void setErrmsg(String errmsg) {
		this.errmsg = errmsg;
	}
	@Override
	public String toString() {
		return "ResultData [errno=" + errno + ", time=" + time + ", errmsg=" + errmsg + ", data=" + data + "]";
	}
}
